package com.codeavatar.catools.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.codeavatar.catools.helper.CaGsonHelper;
import com.codeavatar.catools.helper.CaPermissionHelper;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public abstract class CaBaseActivity extends AppCompatActivity implements View.OnClickListener {

    protected Activity gActivity;
    protected LayoutInflater gLayoutInflater;
    protected Bundle gBundleExtras;
    protected CaPermissionHelper gPermissionHelper;
    protected CaGsonHelper gGsonHelper;

    //++++++++++++++++++++++++++++++++++++++
    //++ 抽象方法
    //++++++++++++++++++++++++++++++++++++++

    protected abstract void initBinding();
    protected abstract View getLayoutView();
    protected abstract void initNavigation();
    protected abstract void initView();
    protected abstract void initEvent();
    protected abstract void initData();

    //++++++++++++++++++++++++++++++++++++++
    //++ 外部方法
    //++++++++++++++++++++++++++++++++++++++

    protected void toStart(Class<?> cls, Bundle extras){
        Intent intent = new Intent(this, cls);
        if(null != extras){
            intent.putExtras(extras);
        }
        startActivity(intent);
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 重写方法
    //++++++++++++++++++++++++++++++++++++++

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.gActivity = this;
        this.initBinding();
        setContentView(this.getLayoutView());
        this.initVariable();
        this.initNavigation();
        this.initView();
        this.initEvent();
        this.initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private void initVariable(){
        this.gLayoutInflater = LayoutInflater.from(this);
        this.gBundleExtras = getIntent().getExtras();
        this.gPermissionHelper = CaPermissionHelper.init();
        this.gGsonHelper = CaGsonHelper.init();
    }
}
